<template>
  <div class="pt44 h100p borderbox">

    <!--top-->
    <div class="disflex bgfff textc jsaround fs16 lh44 c78 bbf7 fix_top zindex999 bgfff" v-if="!loaded">
      <div class="lh44 bgfff" :class="menu_id == 0 ? 'bbblue_2 cblue fbold' : '' " @click="menu_tap(0)">AI分析</div>
      <div class="lh44 bgfff" :class="menu_id == 1 ? 'bbblue_2 cblue fbold' : '' " @click="menu_tap(1)">互动记录</div>
    </div>
    <cover-view class="disflex bgfff textc jsaround fs16 lh44 c78 bbf7 fix_top zindex999 bgfff" v-else>
      <cover-view class="lh44 bgfff" :class="menu_id == 0 ? 'bbblue_2 cblue fbold' : '' " @click="menu_tap(0)">AI分析</cover-view>
      <cover-view class="lh44 bgfff" :class="menu_id == 1 ? 'bbblue_2 cblue fbold' : '' " @click="menu_tap(1)">互动记录</cover-view>
    </cover-view>


    <div  v-show="menu_id == 0">
      <AI></AI>
    </div>
    <div v-show="menu_id == 1" class="pt15 pl15 pr15 h100p borderbox">
      <div class="pt26 bgfff h100p">
        <Log :logs="acitveRecord" :istop="1" :type="'2'"></Log>
      </div>


      <!--bottom-->
      <div class="textc lh42 fs12 ca8 bgf5f6" v-if="nodata">- 到底了，看看其他的吧 -</div>
    </div>


  </div>
</template>

<script>
  import AI from '@/components/AI' //
  import Log from '@/components/log' //
  import WXAJAX from '../../utils/request'
  import util from '../../utils/index'
  import { mapActions } from 'vuex';

  export default {
    name: '',
    components: {AI,Log},
    data() {
      return{
        menu_id:0 ,
        loaded: false,
        acitveRecord: [{time:[]}],//互动记录
        seeType: {
          1: {
            title: '名片',
            1: '现在沟通，效率更高哦',
            4: '成交有望'
          },
          2: {
            title: '产品',
            1: '尽快把握商机',
            4: '可标注为重点客户',
          },
          3: {
            title: '官网',
            1: '有望合作',
            4: '可标注为重点客户',
          },
          4: {
            title: '动态',
            1: '合作意向很强烈',
            4: '成单在望',
          }
        },
        page: 1,
        isLoading: false,//是否在加载
        nodata: false,//是否已经没有数据
      }
    },
    mounted() {
      wx.setNavigationBarTitle({
        title: "客户分析"
      });

    },
    onShow(){
      setTimeout(() => {
        this.loaded = true;
      }, 3*1000);
    },
    onUnload(){
      wx.setStorageSync('AIUserId' , 0 );
      this.loaded = false;
      this.acitveRecord = [{time:[]}];
      this.menu_id = 0;
      this.page = 1;
    },
    onHide(){
    },
    onReachBottom() {
      let v = this;
      if(v.menu_id == 0) return ;
      v.getSeeRecordList();
    },
    methods: {
      ...mapActions(['setCurrentClient']),
      menu_tap(id){
        this.menu_id = id ;
        if(id == 1 && this.acitveRecord[0].time.length == 0){
          this.getSeeRecordList();
        }
        wx.showLoading();
        setTimeout(function () {
          wx.hideLoading();
        },1500);
      },
      getSeeRecordList() {//互动记录
        let v = this;

        if (v.isLoading) {
          return
        }
        v.isLoading = true;

        WXAJAX.POST({
          entranceType: 1,
          pageNum: this.page,
          userId: wx.getStorageSync('AIUserId')
        }, '', '/seeRecord/getSeeRecordList').then((data) => {

          wx.hideLoading();
          if (data) {
            let item = {},
              _datas = [];
            v.page == 1 && (v.acitveRecord = [] );

            data.forEach(function (i, k) {
              var time = '',
                info = '' ;

              info = v.seeType[i.seeType][1];

              time = util.getdate(i.createTime, 'monthTime');
              time = time.split(' ');

              item = {
                time: time,//页面显示时间
                logo: i.logo,
                see: v.seeType[i.seeType].title,
                action: '查看',
                name: i.nickName || '',
                num : i.num,
                info : info
              };
              _datas.push(item);
            });
            v.acitveRecord = [...v.acitveRecord, ..._datas];
            v.page++;
          }
          setTimeout(function () {
            v.isLoading = false;
          }, 500);
        }).catch((err) => {
          console.log(err);
          wx.hideLoading();
          if (err.code == 204) {
            v.nodata = true;
          }
          setTimeout(function () {
            v.isLoading = false;
          }, 500);
        });
      },
    }
  }
</script>

<style>

</style>

























